package com.ruoyi.web.controller.linkage.permission;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.permission.domain.permission;
import com.ruoyi.permission.service.IpermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 菜单权限Controller
 *
 * @author pengjie
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/permission/permission")
public class permissionController extends BaseController
{
    @Autowired
    private IpermissionService permissionService;

    /**
     * 查询菜单权限列表
     */
    @PreAuthorize("@ss.hasPermi('permission:permission:list')")
    @GetMapping("/list")
    public TableDataInfo list(permission permission)
    {
        startPage();
        List<permission> list = permissionService.selectpermissionList(permission);
        return getDataTable(list);
    }

    /**
     * 导出菜单权限列表
     */
    @PreAuthorize("@ss.hasPermi('permission:permission:export')")
    @Log(title = "菜单权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, permission permission)
    {
        List<permission> list = permissionService.selectpermissionList(permission);
        ExcelUtil<permission> util = new ExcelUtil<permission>(permission.class);
        util.exportExcel(response, list, "菜单权限数据");
    }

    /**
     * 获取菜单权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('permission:permission:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(permissionService.selectpermissionById(id));
    }

    /**
     * 新增菜单权限
     */
    @PreAuthorize("@ss.hasPermi('permission:permission:add')")
    @Log(title = "菜单权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody permission permission)
    {
        return toAjax(permissionService.insertpermission(permission));
    }

    /**
     * 修改菜单权限
     */
    @PreAuthorize("@ss.hasPermi('permission:permission:edit')")
    @Log(title = "菜单权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody permission permission)
    {
        return toAjax(permissionService.updatepermission(permission));
    }

    /**
     * 删除菜单权限
     */
    @PreAuthorize("@ss.hasPermi('permission:permission:remove')")
    @Log(title = "菜单权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(permissionService.deletepermissionByIds(ids));
    }
}
